/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import model.Account;


/**
 *
 * @author adriano
 */
public class AccountDAO implements DAO{

	final static Logger logger = Logger.getLogger(AccountantDAO.class);
	
    private final DataSource dataSource;

    public AccountDAO() {
        dataSource = new DataSource();
    }
    
    
    
    public void create(Object o) {
        try {

            String sql = "INSERT INTO planAccount VALUES (null,?,?,?,?,?)";
            PreparedStatement ps = dataSource.getConnection().prepareStatement(sql);
            Account account = (Account) o;

            ps.setString(1,account.getLstPlanoDeContas().toLowerCase());
            ps.setString(2,account.getLstSubGrupoDeContas().toString());
            ps.setString(3,account.getLstGrupoDeContas().toString());
            ps.setString(4,account.getLstStatus());
            ps.setString(5, account.getTxtDescricao().toLowerCase());
           
          

            int res = ps.executeUpdate();
            ps.close();
            if (res == 0) {
               
            	logger.error("CONTADAO.CREATE_Nenhuma conta criada !");

            }
        } catch (SQLException e) {
        	
           System.out.println(e.getMessage());
           
        	logger.error("CONTADAO.CREATE  - ", e);

        }
    }

    public void delete(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); 
    }

    public void update(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); 
    }

    
    public Object read(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); 
    }
    
    
     public void closeDAO() {
        dataSource.closeConnection();
    }
    
}
